package io.kubesphere.devops.core;

import io.kubesphere.devops.common.ExecutorRule;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class RuleExecutor {
    private static ConcurrentMap<String, ExecutorRule> ruleHolder = new ConcurrentHashMap<String, ExecutorRule>();

    public static ExecutorRule registExecutorRule(String name, ExecutorRule executorRule) {
        return ruleHolder.put(name, executorRule);
    }

    public static ExecutorRule loadExecutorRule(String name) {
        if (ruleHolder.get(name) == null) {
            ExecutorRule executorRule = SpringContextUtils.getBean(name);
            if (executorRule == null) {
                return null;
            }
            registExecutorRule(name, executorRule);
        }
        return ruleHolder.get(name);
    }

}
